<template>
    <div class="order-report">
        <div class="report-table-top-title">升级包验证</div>
        <div class="report-table-form1">
            <div class="report-table-form1-line">
                <div
                    class="report-table-form1-item word samll"
                    style="width: 80px; text-align: right"
                >
                    升级包名称:
                </div>
                <div class="report-table-form1-item" style="width: 220px">
                    <el-input
                        class="items"
                        size="small"
                        placeholder="请输入升级包名称"
                        v-model="searchParam.packageName"
                    ></el-input>
                </div>
                <div
                    class="report-table-form1-item word samll"
                    style="width: 80px; text-align: right"
                >
                    设备类型:
                </div>
                <div class="report-table-form1-item" style="width: 220px">
                    <el-select
                        class="items"
                        v-model="searchParam.terminalType"
                        size="small"
                    >
                        <el-option label="全部" value=""></el-option>
                        <el-option
                            v-for="(item, index) in terminalTypeList"
                            :key="index"
                            :label="item.terminalTypeName"
                            :value="item.terminalType"
                        ></el-option>
                    </el-select>
                </div>
                <div
                    class="report-table-form1-item word samll"
                    style="width: 80px; text-align: right"
                >
                    状态:
                </div>
                <div class="report-table-form1-item" style="width: 220px">
                    <el-select
                        class="items"
                        v-model="searchParam.upgradeStatus"
                        filterable
                        placeholder="请选择"
                        size="small"
                    >
                        <el-option label="全部" :value="null"></el-option>
                        <el-option
                            v-for="(item, index) in statusList"
                            :key="index"
                            :label="item.name"
                            :value="item.value"
                        ></el-option>
                    </el-select>
                </div>
                <div style="margin-top: 20px">
                    <div
                        class="report-table-form1-item word samll"
                        style="width: 80px; text-align: right"
                    >
                        经营类型:
                    </div>
                    <div class="report-table-form1-item" style="width: 220px">
                        <el-select
                            v-model="searchParam.managementType"
                            class="items"
                            placeholder="请选择"
                            size="small"
                        >
                            <el-option label="全部" value=""></el-option>
                            <el-option
                                v-for="(item, index) in $store.state.typeList"
                                :key="index"
                                :label="item.managementTypeName"
                                :value="item.managementType"
                            ></el-option>
                        </el-select>
                    </div>

                    <div
                        class="report-table-form1-item word samll"
                        style="width: 80px; text-align: right"
                    >
                        创建时间:
                    </div>
                    <div class="report-table-form1-item">
                        <el-date-picker
                            v-model="searchParam.beginTime"
                            type="date"
                            size="small"
                            class="items"
                            value-format="yyyy-MM-dd"
                            format="yyyy-MM-dd"
                            placeholder="选择日期时间"
                        >
                        </el-date-picker>

                        <span>至:</span>
                        <el-date-picker
                            v-model="searchParam.endTime"
                            type="date"
                            class="items"
                            size="small"
                            value-format="yyyy-MM-dd"
                            format="yyyy-MM-dd"
                            placeholder="选择日期时间"
                        >
                        </el-date-picker>
                    </div>
                    <el-button type="primary" size="small" @click="reSearch"
                        >查询</el-button
                    >
                    <el-button
                        type="primary"
                        plain
                        size="small"
                        @click="initParams"
                        >重置</el-button
                    >
                    <el-button
                        type="primary"
                        size="small"
                        @click="$emit('add', {})"
                        >添加升级包</el-button
                    >
                </div>
            </div>
        </div>
        <div class="page-padding-gray-small"></div>
        <div class="report-table-wrapper">
            <el-table
                :header-cell-style="headerCellStyle"
                size="small"
                :data="tabData"
                border
                style="width: 100%"
            >
                <el-table-column
                    prop="managementTypeName"
                    label="经营类型"
                    min-width="160"
                    show-overflow-tooltip
                ></el-table-column>
                <el-table-column
                    prop="packageName"
                    label="升级包名称"
                    min-width="160"
                    show-overflow-tooltip
                ></el-table-column>
                 <el-table-column
                    prop="forceUpgrade"
                    label="是否强制升级"
                    min-width="160"
                    show-overflow-tooltip
                >
                    <template slot-scope="scope">
                        {{ scope.row.forceUpgrade === 1 ? '是' : '否' }}
                    </template>
                </el-table-column>
                <el-table-column
                    prop="packageVersionCode"
                    label="升级包版本号"
                    min-width="160"
                    show-overflow-tooltip
                ></el-table-column>
               
                <el-table-column
                    prop="md5"
                    label="md5"
                    min-width="160"
                    show-overflow-tooltip
                ></el-table-column>
                <el-table-column
                    prop="upgradePackageFileTypeName"
                    label="升级包文件类型"
                    min-width="160"
                    show-overflow-tooltip
                ></el-table-column>
                <el-table-column
                    prop="terminalTypeName"
                    label="设备类型"
                    min-width="160"
                    show-overflow-tooltip
                ></el-table-column>
                <el-table-column
                    prop="upgradeStatusName"
                    label="状态"
                    min-width="160"
                    show-overflow-tooltip
                ></el-table-column>
                <el-table-column
                    prop="internalPackageVersionCode"
                    label="升级包内部版本号"
                    min-width="160"
                    show-overflow-tooltip
                ></el-table-column>
                <el-table-column
                    prop="packageSize"
                    label="文件大小 (MB)"
                    min-width="160"
                    show-overflow-tooltip
                >
                </el-table-column>
                <el-table-column
                    prop="createTime"
                    label="创建时间"
                    min-width="160"
                    show-overflow-tooltip
                ></el-table-column>
                <el-table-column
                    prop="updateTime"
                    label="更新时间"
                    min-width="160"
                    show-overflow-tooltip
                ></el-table-column>
                <el-table-column fixed="right" label="操作" width="150px">
                    <template slot-scope="scope">
                        <el-dropdown trigger="click">
                            <span class="el-dropdown-link">
                                操作<i
                                    class="el-icon-arrow-down el-icon--right"
                                ></i>
                            </span>
                            <el-dropdown-menu slot="dropdown">
                                <!-- <el-dropdown-item
                                    @click.native="$emit('manage', scope.row)"
                                    >管理验证场所</el-dropdown-item
                                > -->
                                <el-dropdown-item
                                    :disabled="
                                        scope.row.upgradeStatusValue !== 5
                                    "
                                    @click.native="showAddShop(scope.row)"
                                    >指定商家</el-dropdown-item
                                >
                                <el-dropdown-item
                                    :disabled="
                                        scope.row.upgradeStatusValue !== 0 &&
                                        scope.row.upgradeStatusValue !== 10
                                    "
                                    @click.native="
                                        updateUpgradeStatus(5, scope.row)
                                    "
                                    >启动验证流程</el-dropdown-item
                                >
                                <el-dropdown-item
                                    :disabled="
                                        scope.row.upgradeStatusValue !== 5
                                    "
                                    @click.native="
                                        updateUpgradeStatus(10, scope.row)
                                    "
                                    >暂停验证流程</el-dropdown-item
                                >
                                <el-dropdown-item
                                    :disabled="
                                        scope.row.upgradeStatusValue !== 5
                                    "
                                    @click.native="
                                        updateUpgradeStatus(15, scope.row)
                                    "
                                    >审核验证成功</el-dropdown-item
                                >
                                <el-dropdown-item
                                    :disabled="
                                        scope.row.upgradeStatusValue !== 5
                                    "
                                    @click.native="
                                        updateUpgradeStatus(20, scope.row)
                                    "
                                    >审核验证失败</el-dropdown-item
                                >
                                <el-dropdown-item
                                    @click.native="
                                        showMS('internalDescription', scope.row)
                                    "
                                    >升级包内部描述</el-dropdown-item
                                >
                                <el-dropdown-item
                                    @click.native="
                                        showMS('externalDescription', scope.row)
                                    "
                                    >升级包外部描述</el-dropdown-item
                                >
                                <el-dropdown-item
                                    :disabled="
                                        scope.row.upgradeStatusValue !== 0
                                    "
                                    @click.native="$emit('add', scope.row)"
                                    >修改升级包</el-dropdown-item
                                >
                                <el-dropdown-item
                                    :disabled="
                                        scope.row.upgradeStatusValue !== 0
                                    "
                                    @click.native="delRow(scope.row)"
                                    >删除升级包</el-dropdown-item
                                >
                            </el-dropdown-menu>
                        </el-dropdown>
                    </template>
                </el-table-column>
            </el-table>
        </div>
        <!-- 分页 -->
        <div class="report-table-block">
            <div class="report-table-block-in">
                <el-pagination
                    background
                    :current-page.sync="currentPage"
                    @current-change="handleCurrentChange"
                    :page-size="pageSize"
                    layout="prev, pager, next, total"
                    :total="totalNum"
                ></el-pagination>
            </div>
        </div>
        <showMS
            :value.sync="isShowMS"
            :msName="msName"
            :currRow="currRow"
        ></showMS>
        <addPlace
            :value.sync="isShowAddShop"
            :currRow="currRow"
            @getList="getList"
        ></addPlace>
    </div>
</template>

<script type="text/ecmascript-6">
import showMS from './components/showMS'
import addPlace from './components/addPlace'
export default {
    components: {
        showMS,
        addPlace
    },
    data: function () {
        return {
            isShowAddShop: false,
            currRow: {},
            msName: '',
            isShowMS: false,
            terminalTypeList: [], // 设备类型
            statusList: [], // 状态列表
            row: null,
            loading: false,
            searchParam: {
                packageName: '',
                terminalType: '',
                beginTime: '',
                managementType: '',
                endTime: '',
                upgradeStatus: null
            },
            agentList: [],
            currentPage: 1,
            pageSize: 10,
            totalNum: 0,
            tabData: []
        }
    },
    mounted () {
    },
    created () {
        this.getOnlyTerminalTypeV2()
        this.upgradeStatusList()
        this.getList()
    },
    watch: {
    },
    props: {
        underLine: null
    },
    methods: {
        showAddShop (item) {
            this.isShowAddShop = true
            this.currRow = item
        },
        showMS (name, row) {
            this.isShowMS = true
            this.msName = name
            this.currRow = row
        },
        initParams () {
            this.searchParam.packageName = ''
            this.searchParam.terminalType = ''
            this.searchParam.beginTime = ''
            this.searchParam.endTime = ''
            this.searchParam.managementType = ''
            this.searchParam.upgradeStatus = null
            this.currentPage = 1
            this.pageSize = 10
            this.getList()
        },
        updateUpgradeStatus (upgradeStatus, row) {
            this.$confirm('确定执行此操作吗?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.$http.get(this.$store.state.IP + `/upgradeManage/updateUpgradeStatus?upgradeStatus=${upgradeStatus}&upgradePackageID=${row.upgradePackageID}`, {
                },
                    {
                        'emulateJSON': false
                    }
                ).then(response => {
                    console.log('-------------------------------------------')
                    response = response.body
                    console.log(response)
                    if (response.ret === '0') {
                        this.$message({
                            message: '操作成功',
                            type: 'success'
                        })
                        this.getList()
                    }
                }, response => {
                })
            }).catch(() => {
            })
        },
        getOnlyTerminalTypeV2 () {
            this.$http.get(this.$store.state.IP + '/system/company/getOnlyTerminalTypeV2?isAll=1',
                {
                    'emulateJSON': false
                }
            ).then(response => {
                console.log('-------------------------------------------')
                response = response.body
                console.log(response)
                if (response.ret === '0') {
                    this.terminalTypeList = response.res
                }
            }, response => {
            })
        },
        upgradeStatusList () {
            this.$http.get(this.$store.state.IP + '/upgradeManage/upgradeStatusList?upgradeStage=0', {
            },
                {
                    'emulateJSON': false
                }
            ).then(response => {
                console.log('-------------------------------------------')
                response = response.body
                console.log(response)
                if (response.ret === '0') {
                    this.statusList = response.res
                }
            }, response => {
            })
        },
        delRow (row) {
            console.log(row)
            this.$confirm('确定删除吗?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                let params = {
                    params: {
                    }
                }
                this.$http.get(this.$store.state.IP + '/upgradeManage/deleteUpgrade?upgradePackageID=' + row.upgradePackageID, params).then(response => {
                    response = response.body
                    console.log(response)
                    if (response.ret === '0') {
                        this.$message({
                            message: '删除成功',
                            type: 'success'
                        })
                        this.getList()
                    }
                }, response => {
                    console.log('调用添加失败')
                })
            }).catch(() => {
            })
        },
        handleCurrentChange (page) {
            // 换页
            this.currentPage = page
            this.getList()
        },
        reSearch () {
            this.currentPage = 1
            this.getList()
        },
        getList () {
            if (this.searchParam.endTime) {
                if (this.searchParam.endTime < this.searchParam.beginTime) {
                    return this.$message({
                        message: '开始时间不能大于结束时间',
                        type: 'warning'
                    })
                }
            }
            // 获取 所有 服务列表
            this.$http.post(this.$store.state.IP + '/upgradeManage/upgradeInfoList', {
                packageName: this.searchParam.packageName,
                managementType: this.searchParam.managementType,
                terminalType: this.searchParam.terminalType,
                upgradeStatus: this.searchParam.upgradeStatus,
                beginTime: this.searchParam.beginTime ? this.searchParam.beginTime + ' 00:00:00' : '',
                endTime: this.searchParam.endTime ? this.searchParam.endTime + ' 23:59:59' : '',
                page: this.currentPage - 1,
                size: this.pageSize,
                upgradeStage: 0
            },
                {
                    'emulateJSON': false
                }
            ).then(response => {
                response = response.body
                this.tabData = []
                if (response.ret === '0') {
                    this.tabData = response.res.list
                    this.totalNum = response.res.total
                }
                if (response.ret !== '0') {
                    console.log('调用获取所有代理商失败')
                }
                console.log('******************************************')
            }, response => {
                console.log('通讯失败')
            })
        }
    }
}
</script>

<style lang="stylus" rel="stylesheet/stylus" scoped>
.el-dropdown-link
    color: #409EFF
    cursor: pointer

.order-report
    width: 100%
    background: #fff
    min-height: calc(100vh - 65px)
    position: relative

    .report-table-top-title
        width: 100%
        height: 64px
        line-height: 64px
        color: #000
        font-size: 18px
        background: #f1f0f5

    .report-table-form1
        width: 100%
        min-height: 40px
        padding: 16px 0 0 22px
        box-sizing: border-box
        background: #fff
        overflow: hidden

        .report-table-form1-line
            min-height: 32px
            margin-bottom: 16px

            .report-table-form1-item
                display: inline-block
                vertical-align: top
                height: 32px
                margin-right: 15px
                line-height: 32px

                &.word
                    margin-right: 0

                &.samll
                    font-size: 15px
                    text-align: left

                &.big
                    margin-right: 100px

    .report-table-block
        width: 100%
        padding-top: 22px
        height: 50px
        background: #fff
        box-sizing: border-box

        .report-table-block-in
            float: right
            padding-right: 17px

    .page-padding-gray-small
        width: 100%
        height: 22px
        background: #f1f0f5

    .page-padding
        width: 100%
        height: 20px
        background: #fff

    .report-table-total
        width: 100%
        font-size: 16px
        color: #409EFF
        padding: 22px
        margin-top: 22px
        box-sizing: border-box
        background: #fff

    .page-all-loading
        position: fixed
        top: 55%
        left: 40%
        width: 200px

.title
    display: inline-block
    min-width: 120px
    text-align: right
    font-weight: bold
    line-height: 35px

.value
    display: inline-block
    line-height: 35px
    min-width: 150px

.items
    width: 200px

.item
    margin-bottom: 0px
</style>

